<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef"> </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive, defineProps } from "vue";
import secureInspectionrouteInfo from "@/api/secure/secureInspectionrouteInfo";
import { Message } from "@arco-design/web-vue";
import tool from "@/utils/tool";
import * as common from "@/utils/common";

const crudRef = ref();

const props = defineProps({
  route_ids: {
    type: Number,
    default: 0,
  },
});

const numberOperation = (newValue, id, numberName) => {
  secureInspectionrouteInfo
    .numberOperation({ id, numberName, numberValue: newValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const switchStatus = (statusValue, id, statusName) => {
  secureInspectionrouteInfo
    .changeStatus({ id, statusName, statusValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const options = reactive({
  id: "flyos_secure_inspectionroute_info",
  rowSelection: {
    showCheckedAll: true,
  },
  pk: "id",
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: "modal",
    width: 600,
  },
  api: secureInspectionrouteInfo.getList,
  recycleApi: secureInspectionrouteInfo.getRecycleList,
  add: {
    show: true,
    api: secureInspectionrouteInfo.save,
    auth: ["secure:inspectionrouteInfo:save"],
  },
  edit: {
    show: true,
    api: secureInspectionrouteInfo.update,
    auth: ["secure:inspectionrouteInfo:update"],
  },
  delete: {
    show: true,
    api: secureInspectionrouteInfo.deletes,
    auth: ["secure:inspectionrouteInfo:delete"],
    realApi: secureInspectionrouteInfo.realDeletes,
    realAuth: ["secure:inspectionrouteInfo:realDeletes"],
  },
  recovery: {
    show: true,
    api: secureInspectionrouteInfo.recoverys,
    auth: ["secure:inspectionrouteInfo:recovery"],
  },
  beforeRequest: (params) => {
    params.route_id = props.route_ids;
  },
  beforeAdd: (formData) => {
    formData.route_id = props.route_ids;
    return true;
  },
  import: {
    show: true,
    url: "secure/inspectionrouteInfo/import",
    templateUrl: "secure/inspectionrouteInfo/downloadTemplate",
    auth: ["secure:inspectionrouteInfo:import"],
  },
  export: {
    show: true,
    url: "secure/inspectionrouteInfo/export",
    auth: ["secure:inspectionrouteInfo:export"],
  },
});

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID",
    },
  },
  {
    title: "节点信息",
    dataIndex: "node_info",
    formType: "input",
    search: true,
  },
  {
    title: "要求",
    dataIndex: "demand",
    formType: "input",
    search: true,
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
]);
</script>
<script>
export default { name: "secure:inspectionrouteInfo" };
</script>
